﻿#region Using
// System
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

// Csla
using Csla;
#endregion // Using

namespace GACAssemblyExporter.Library
{
    /// <summary>
    /// Assembly class
    /// </summary>
    public class AssemblyInfo: ReadOnlyBase<AssemblyInfo>
    {
        #region Constructors
        /**********************************************************************
         * Constructors
         *********************************************************************/
        private AssemblyInfo() { this.Id = Guid.Empty; }
        #endregion // Constructors

        #region Properties
        /**********************************************************************
         * Properties
         *********************************************************************/
        public Guid Id { get; private set; }
        public string Name { get; private set; }
        public VersionInfoList VersionList { get; private set; }
        #endregion // Properties

        #region Data Portal Methods
        /**********************************************************************
         * Data Portal Methods
         *********************************************************************/
        /// <summary>
        /// The data portal fetch method
        /// </summary>
        /// <param name="criteria"></param>
        private void DataPortal_Fetch(RootDirectoryCriteria criteria)
        {
            if (Directory.Exists(criteria.RootDirectory))
            {
                this.Id = Guid.NewGuid();
                DirectoryInfo di = new DirectoryInfo(criteria.RootDirectory);
                this.Name = di.Name;
                this.VersionList = VersionInfoList.Get(criteria.RootDirectory);
            }// if the directory exists
        }// of DataPortal_Fetch(RootDirectoryCriteria)
        #endregion // Data Portal Methods

        #region Factory Methods
        /**********************************************************************
         * Factory Methods
         *********************************************************************/
        /// <summary>
        /// Gets the assmebly info for the directory
        /// </summary>
        /// <param name="assemblyDirectory"></param>
        /// <returns></returns>
        internal static AssemblyInfo Get(string assemblyDirectory)
        {
            return DataPortal.Fetch<AssemblyInfo>(new RootDirectoryCriteria() { RootDirectory = assemblyDirectory });
        }// of AssemblyInfo Get(string)
        #endregion // Factory Methods
    }// of class Assembly
}// of namespace GACAssemblyExporter.Library